﻿using Common;
using IBLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DemoManageSys.Areas.Filters;
using Models.DTO;
using Microsoft.AspNetCore.Mvc;
using Models;

namespace DemoManageSys.Areas.API.Controllers
{
    [Area("API")]
    public class ProductInfoController : Controller
    {
        private IProductInfoBLL _productInfoBLL;

        public ProductInfoController(
            IProductInfoBLL productInfoBLL
            )
        {
            _productInfoBLL = productInfoBLL;
        }

        #region 显示视图
        public IActionResult ListView()
        {
            return View();
        }

        public IActionResult CreateView()
        {
            return View();
        }

        public IActionResult EditView()
        {
            return View();
        }
        #endregion

        #region 获取的方法 (GetProductInfoes)
        [HttpGet]
        public IActionResult GetProductInfo(int page, int limit, string productName,string categoryID)
        {
            int count;
            //调用BLL的查询方法
            List<GetProductInfoDTO> getProductInfoDTOs = _productInfoBLL.GetProductInfo(page, limit, productName, categoryID, out count);

            ReturnResule result = new ReturnResule()
            {
                Code = 0,
                Msg = "获取成功",
                Data = getProductInfoDTOs,
                Count = count
            };

            return Json(result);
        }
        #endregion ()

        #region 添加的方法 (CreateProductInfo)
        [HttpPost]
        public IActionResult CreateProductInfo([FromForm] ProductInfo prod)
        {
            //实例化对象
            ReturnResule resule = new ReturnResule();
            string msg;//定义返回消息
            resule.IsSuccess = _productInfoBLL.CreateProductInfo(prod, out msg);//调用方法传值
            if (resule.IsSuccess)
            {
                resule.Code = 200;
                resule.Msg = msg;
            }
            else
            {
                resule.Msg = msg;

            }
            return Json(resule);
        }
        #endregion

    }
}